package com.sq.partner.manager.service.impl;

import com.sq.partner.manager.common.DictCache;
import com.sq.partner.manager.dao.ICoreDeptDao;
import com.sq.partner.manager.dao.IGatewayCustomerDao;
import com.sq.partner.manager.dao.IGatewayPolicyDao;
import com.sq.partner.manager.dao.LifeDataExportDao;
import com.sq.partner.manager.mybatis.model.DictDto;
import com.sq.partner.manager.mybatis.model.LifeDataExportVO;
import com.sq.partner.manager.service.LifeDataExportService;
import com.sq.partner.manager.util.Page;
import com.sq.partner.manager.util.StrUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Service;

import java.sql.SQLException;
import java.util.List;
import java.util.Map;

/**
 * 2022/8/25 16:45
 */
@Service
public class LifeDataExportServiceImpl implements LifeDataExportService {
	@Autowired
	private LifeDataExportDao lifeDataExportDao;


	List<DictDto> channelNameList = DictCache.getDict("belong_to_channel");
	/**
	 * 通过条件查询意健险数据
	 * @param page
	 * @return
	 */
	@Override
	public Page<Map<String, Object>> queryLifeDataByCriteria(Page<Map<String, Object>> page) throws Exception {
		//渠道代码
		List<Map<String, Object>> lifeDataExportList = lifeDataExportDao.queryLifeDataByCriteria(page);

		if (channelNameList == null || channelNameList.size() == 0){
			this.channelNameList = DictCache.getDict("belong_to_channel");
		}
		//添加渠道名称
		for (Map<String, Object> map : lifeDataExportList) {
			String channleCode = (String) map.get("channlecode");
			map.put("channleName","");
			for (DictDto dictDto : channelNameList) {
				if (dictDto.getCode().equals(channleCode) && StrUtil.isNotEmpty(channleCode)){
					map.put("channleName",dictDto.getCodeName());
				}
			}
		}
		page.setData(lifeDataExportList);
		return page;
	}

	@Override
	public Page<Map<String, Object>> queryLifePolicyAll(Page<Map<String, Object>> page) throws Exception {
		//渠道代码
		Page lifeDataExportAll = lifeDataExportDao.queryLifePolicyAll(page);
		return lifeDataExportAll;
	}
}
